class CommentsController < ApplicationController
  def index
    @comments = Comment.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @comments }
    end
  end

  # GET /ingredients/1
  # GET /ingredients/1.xml
  def show
    @comments = Comment.find_all_by_recipe_id(params[:recipe_id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @comments }
    end
  end

  # GET /ingredients/new
  # GET /ingredients/new.xml
  def new
    @comments = Comment.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @comments }
    end
  end

  # GET /ingredients/1/edit
  def edit
    @comments = Comment.find(params[:recipe_id])
  end

  # POST /ingredients
  # POST /ingredients.xml
  def create
    @new_comment = Comment.new(:recipe_id => params[:recipe_id], :text => params[:text])

    respond_to do |format|
      if @new_comment.save
         @comments = Comment.find_all_by_recipe_id(params[:recipe_id])
         format.js
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @new_comment.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /ingredients/1
  # DELETE /ingredients/1.xml
  def destroy
    @comments = Comment.find(params[:recipe_id])
    @comments.destroy

    respond_to do |format|
      format.html { redirect_to(comments_url) }
      format.xml  { head :ok }
    end
  end
end
